const process = require('process')
const puppeteer = require('puppeteer')
const {username, password} = require('./config.json')
const siteurl = 'http://10.51.3.40/'

async function run() {
    const browser = await puppeteer.launch({
        headless: true,
        args: ['--no-sandbox', '--disable-setuid-sandbox']
    })
    const page = await browser.newPage()
    await page.setViewport({
        width: 1024, height: 768, deviceScaleFactor: 1
    })
    await page.setJavaScriptEnabled(true)
    await page.goto(siteurl)
    page.on('response', resp => {
        console.log(resp.url())
    })
    /* await page.screenshot({path: 'first.png'}) */
//    await page.waitForResponse(resp => {
//		console.log('Wait for login response...')
//		console.log(resp.url())
//        return resp.status() === 200
//    })
    await page.waitForSelector('button#logout')
    await page.evaluate(() => {
		document.getElementById('logout').click()
    })
    await page.evaluate(() => {
		document.querySelector('.dialog.confirm .btn-confirm').click()
    })
    await page.waitForSelector('#login-account')
    //await page.screenshot({path: 'logout.png'})
	await browser.close()
}

run().catch(err => {
    console.log(err)
    process.exit(1)
})
